# -*- coding: utf-8 -*-
# @Time    : 2019/5/15 11:30
# @Author  : Igor
# @File    : 同步锁.py
# @Software: PyCharm
# 参考博客 : https://www.cnblogs.com/guobaoyuan/p/6832470.html

import time
import threading

num = 100
lock = threading.Lock()


def sud_num():
    global num
    lock.acquire()    # 加锁
    temp = num
    time.sleep(0.01)
    num = temp-1
    lock.release()   # 解锁


new_list = []
for i in range(100):
    t = threading.Thread(target=sud_num)
    t.start()
    new_list.append(t)

for f in new_list:
    f.join()

print('Result:', num)

